// -----------------------------
// Author: 		Dhaenens Gert 
// Creation: 	10/9/2014 7:54:43 PM				
// -----------------------------

#ifndef _RenderManager_h
#define _RenderManager_h

#include "Common.h"

class Application;
class Window;
class Scene;
class RenderPass;
class Mutex;

enum class RenderState
{
	Default,
	DefaultNoCull,
	Wireframe,
};

class RenderManager
{
public:
	RenderManager();
	~RenderManager();

	Bool				Init(Application* lpApp, Bool bVSync);

	void				Flush(Application* lpApp, Scene* lpScene);
	Bool				Resize(Application* lpApp);

	void				SetRenderState(RenderState state, Bool bVerbose = true);

	RenderState			GetRenderState() const;
	RenderPass*			GetRenderPass(const AString& name) const;

	IRenderDevice*		GetDevice() const;

	Mutex*				GetMutex() const;

	void				SaveScreenshot();
	
private:

	Bool				CreateDependentResources(Application* lpApp);

	IRenderDevice*		m_lpDevice;
	IRenderTarget*		m_lpOutputTarget;
	IDepthStencil*		m_lpDepthStencil;

	IRenderTarget*		m_lpPositionTarget;
	IRenderTarget*		m_lpNormalTarget;
	IRenderTarget*		m_lpAlbedoTarget;
	IRenderTarget*		m_lpAmbientTarget;

	IRenderTarget2D*	m_lpRenderTarget2D;
	IRenderTarget*		m_lpRawRenderTarget3D;
	IRenderTarget*		m_lpPostRenderTarget3D;

	RenderState			m_RenderState;
	IRasterizerState*	m_lpDefaultRasterizer;
	IRasterizerState*	m_lpDefaultNoCullRasterizer;
	IRasterizerState*	m_lpWireframeRasterizer;

	Mutex*				m_lpMutex;
	Bool				m_bVSync; 
	UInt32				m_ScreenshotIdx;

	vector<RenderPass*>	m_Passes;

	RenderManager(const RenderManager& refRenderManager);
	RenderManager& operator=(const RenderManager& refRenderManager);
};

#endif